<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
    {literal}
        google.load("visualization", "1", {packages:["corechart"]});
        google.setOnLoadCallback(drawChart);
        function drawChart() 
        {
            var data = new google.visualization.DataTable();
            data.addColumn('datetime', 'Time');
            data.addColumn('number', 'Speed');
            data.addRows( {/literal}{$torrent|count}{literal} );
            {/literal}
                {foreach from=$torrent item=t name=speeds}
                    data.setValue( {$smarty.foreach.speeds.index}, 1, {$t.Speed} );
                    var dateobj = new Date( {$t.date.year}, {$t.date.month}, {$t.date.day}, {$t.date.hour}, {$t.date.minute}, {$t.date.second}, {$t.date.millisecond} );
                    data.setValue( {$smarty.foreach.speeds.index}, 0, dateobj );
                {/foreach}
            {literal}

            var chart = new google.visualization.LineChart(document.getElementById('speeds_div'));
            chart.draw( data, 
                {
                    width: 1000, height: 300,
                    title: 'Speed in time comparison',
                    vAxis: {title: 'Speed', minValue: -2, maxValue: 2},
                    hAxis: {title: 'Time', minValue: 0, maxValue: 15},
                    legend: 'none'
                });
        }

        google.setOnLoadCallback(drawChart_watcher);
        function drawChart_watcher() 
        {
            var data = new google.visualization.DataTable();
            data.addColumn('datetime', 'Time');
            data.addColumn('number', 'Downloads');
            data.addRows( {/literal}{$torrent_watchlist|count}{literal} );
            {/literal}
                {foreach from=$torrent_watchlist item=t name=speeds}
                    data.setValue( {$smarty.foreach.speeds.index}, 1, {$t.Downloads} );
                    var dateobj = new Date( {$t.date.year}, {$t.date.month}, {$t.date.day}, {$t.date.hour}, {$t.date.minute}, {$t.date.second}, {$t.date.millisecond} );
                    data.setValue( {$smarty.foreach.speeds.index}, 0, dateobj );
                {/foreach}
            {literal}

            var chart = new google.visualization.LineChart(document.getElementById('downloads_div'));
            chart.draw( data, 
                {
                    width: 1000, height: 300,
                    title: 'Downloads in time comparison',
                    vAxis: {title: 'Downloads'},
                    hAxis: {title: 'Time', minValue: 0, maxValue: 15},
                    legend: 'none'
                });
        }
    {/literal}
</script>

<a href="/torrents/list">Back to list</a>
<h1>{$torrent_details.Torrent}</h1>

<div id="speeds_div" ></div>
<div id="downloads_div" ></div>